home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Snippets / Development Tools & Languages / DTSCPlusLibrary / Sources / DTSCPlusLibrary.h < prev    next >
Encoding:
Text File  |  1993-01-14  |  6.6 KB  |  253 lines  |  [TEXT/MPS ]

  1. /* _________________________________________________________________________________________________________ //
  2.   Copyright © 1992-93 Apple Computer, Inc. All rights reserved.
  3.   Macintosh Developer Technical Support.C++ Macintosh Toolbox Framework.
  4.   Date: Monday, June 22, 1992 11:44:15
  5.   Revision comments are at the end of this file.
  6.   ---
  7.   DTSCPlusLibrary.h contains all the global data and definitions needed when building
  8.   more DTS C++ libraries. Every class should have this file included.
  9.   DTSLibrary.h contains all the header information.
  10.   _________________________________________________________________________________________________________ */
  11. // Declare label for this header file
  12. #ifndef _DTSCPLUSLIBRARY_
  13. #define _DTSCPLUSLIBRARY_
  14.  
  15.  
  16. // _________________________________________________________________________________________________________ //
  17. // GLOBAL DEFINITIONS
  18.  
  19. // TESTING, used for flagging that we use test code inside the classes and frameworks
  20. // TESTLEVEL0        - user friendly alerts as part of the application
  21. // TESTLEVEL1     - minor test level (detailed error message in alert box)
  22. // TESTLEVEL2     - semi-major test level (high level debuggers)
  23. // TESTLEVEL3     - major test level (low level debuggers)
  24. // future: TESTLOG1        - trigger a file log of information
  25. //            TESTLOG2        - trigger a file log of information from a low level debugger
  26.  
  27. #define TESTLEVEL3
  28.  
  29. // MPW C++, 1 = code for MPW C++
  30. // #define MPWC++ 
  31.  
  32. // ZTC, 1 = code for ZTC
  33. // #define ZTC 
  34.  
  35. // SLM, code used with Shared Library Manager Support, 1 = true
  36. // #define SLM 
  37.  
  38. // _________________________________________________________________________________________________________ //
  39. // GENERAL INCLUDE FILES
  40.  
  41. //    Toolbox Include Files
  42. #ifndef __TYPES__
  43. #include <Types.h>
  44. #endif
  45.  
  46. #ifndef __STRING__
  47. #include <String.h>
  48. #endif
  49.  
  50. #ifndef __MEMORY__
  51. #include <Memory.h>
  52. #endif
  53.  
  54. #ifndef __DIALOGS__
  55. #include <Dialogs.h>
  56. #endif
  57.  
  58. #ifndef __APPLEEVENTS__
  59. #include <AppleEvents.h>
  60. #endif
  61.  
  62. // C++ library code
  63. #include <stream.h>
  64. #include <stdlib.h>
  65. #include <StdIO.h>
  66. #include <stdarg.h>
  67.  
  68. #ifdef SLM
  69. #include <LibraryManagerClasses.h>
  70. #endif
  71.  
  72. // FUNCTION PROTOTYPES
  73. // I found out that these following former inlined functions were not inlined,
  74. // the linker screamed, so they now live in a .cp file (sigh), remember to include
  75. // the CPlusLibrary.cp file when using the other .cp files!
  76.  
  77. short clen(char *cptr);
  78. void c2p(char *cptr);
  79. void p2c(StringPtr cptr);
  80. void Pstrcpy(StringPtr d, StringPtr s);
  81. void ConcatPStrings(Str255 first, Str255 second);
  82. Boolean CompareStr255(const Str255 *first, const Str255 *second);
  83.  
  84. void vxdebugstr(char* format,...);
  85.  
  86. void ErrorWindow(char* message);
  87.  
  88. // INLINE FUNCTIONS
  89. // _________________________________________________________________________________________________________ //
  90. // 1: BASIC MANIPULATION INLINES
  91.  
  92. // Min/Max functions, oh so useful.
  93. inline short Min(const short a,
  94.                  const short b)
  95. {
  96.     return a < b ? a : b;                        // Just returns the minimum of the two shorts.
  97. }                                                // Min 
  98.  
  99.  
  100. inline short Max(const short a,
  101.                  const short b)
  102. {
  103.     return a > b ? a : b;                        // Just returns the maximum of the two shorts.
  104. }                                                // Max 
  105.  
  106.  
  107. inline pascal    Byte Decimal2BCD(Byte n) 
  108. {
  109.     return ((n / 10) << 4) + (n % 10); 
  110. }
  111.  
  112. inline pascal    Byte BCD2Decimal(Byte n) 
  113. {
  114.     return ((n >> 4) * 10) + (n & 0x0f);
  115. }
  116.  
  117. // extract hi word and lo word from a longword
  118. #define HiWrd(aLong)        ((short) (((aLong) >> 16) & 0xFFFF)) 
  119. #define LoWrd(aLong)        ((short) ((aLong) & 0xFFFF)) 
  120.  
  121.  
  122.  
  123. // _________________________________________________________________________________________________________ //
  124. // MACROS AND DEBUGGING
  125. // ASSERT Function, used for testing conditions and flagging error states.
  126. // Example: vdebugstr("The error message from Foo is %i", fError);
  127.  
  128. // We need to load in certain include files if we want to use the alert boxes for
  129. // high level ASSERT functions (we also need to include the GUIApplication.r file
  130. // into the project).
  131.  
  132. #if (defined TESTLEVEL0 || defined TESTLEVEL1)
  133. #include "ApplicationResources.h"
  134. #endif
  135.  
  136.  
  137. //  Define this flag if you want file and line information as part of the message.
  138. #define FILELINEINFO
  139.  
  140.  
  141. //     fileinfo will keep track of the current file and line in a global.
  142. static char fileNameArray[32];
  143. static char lineNumberArray[32];
  144.  
  145.  
  146. #if (defined TESTLEVEL0 || defined TESTLEVEL1)
  147. inline void AlertUser(Str255 theMessage)
  148. {
  149.     short itemHit;
  150.     
  151.     if(!(AEInteractWithUser(kNoTimeOut, nil, nil)))                // could we interact with the user?
  152.     {
  153.         ParamText(theMessage, 0, 0,0);
  154.         itemHit = Alert(kUserAlert, nil);
  155.     }
  156. }
  157. #endif
  158.  
  159. inline void fileinfo(char *file, int line)
  160. {
  161.     sprintf(fileNameArray, "File %s ", file);
  162.     sprintf(lineNumberArray, " Line %d  #", line);
  163. }
  164.  
  165.  
  166.  
  167.  
  168. //    ASSERT MACROS
  169.  
  170. //    ASSERT, small (and quick assert),  if assertion is false it will print out 
  171. //     a message
  172. //    Use: ASSERT(false, "Problems with TSoundRecorder");
  173.  
  174. #if (defined TESTLEVEL0 || defined TESTLEVEL1)
  175. #define ASSERT(condition,debugMsg) do {                        \
  176.     if(condition == 0)                                        \
  177.     {                                                        \
  178.         AlertUser(debugMsg);                                \
  179.     }                                                        \
  180.    } while (0)                                                \
  181.  
  182. #elif (defined TESTLEVEL2 || defined TESTLEVEL3)
  183. #define ASSERT(condition,debugMsg) do {                        \
  184.     if(condition == 0)                                        \
  185.     {                                                        \
  186.         DebugStr(debugMsg);                                    \
  187.     }                                                        \
  188.    } while (0)
  189. #else
  190. #define ASSERT(condition,debugMsg) ((void) 0)
  191. #endif
  192.  
  193.  
  194. //    VASSERT, if assertion is false it will print out file, line, message and possible variable
  195. //    Use: VASSERT(false,("Problems with %d", anErr));
  196.  
  197. #if (defined TESTLEVEL0)
  198. ##define VASSERT(condition,debugMsg) do {                    \
  199.     if(condition == 0)                                        \
  200.     {                                                        \
  201.         vxdebugstr  debugMsg;                                \
  202.     }                                                        \
  203.    } while (0)
  204.  
  205. #elif (defined TESTLEVEL1 || defined TESTLEVEL2 ||  defined TESTLEVEL3)
  206. #define VASSERT(condition,debugMsg) do {                    \
  207.     if(condition == 0)                                        \
  208.     {                                                        \
  209.         fileinfo(__FILE__, __LINE__);                        \
  210.         vxdebugstr  debugMsg;                                \
  211.     }                                                        \
  212.    } while (0)
  213.    
  214. #else
  215. #define (condition,debugMsg) ((void) 0)
  216. #endif
  217.  
  218.  
  219. // Option key triggered debug breaks:
  220. inline void ODebugger()
  221. // Drop into Debugger only if the option key is pressed.
  222. {
  223.     KeyMap k;
  224.     GetKeys(k);
  225.     if (((char*)k)[7] & 0x04)                    // check for option key in KeyMap
  226.         Debugger();
  227. }
  228.  
  229.  
  230. inline void ODebugStr(Str255 string)
  231. // Drop into DebugStr only if the option key is pressed.
  232. {
  233.     KeyMap k;
  234.     GetKeys(k);
  235.     if (((char*)k)[7] & 0x04)                    // check for option key in KeyMap
  236.         DebugStr(string);
  237. }
  238.  
  239.  
  240. #endif
  241.  
  242. // _________________________________________________________________________________________________________ //
  243.  
  244.  
  245. /*    Change History (most recent last):
  246.   No    Init.    Date        Comment
  247.   1        khs        9/10/92        New file
  248.   2        khs        11/26/92    Added ASSERT macros and testing levels
  249.   3        khs        1/14/93        Cleanup
  250. */
  251.  
  252.  
  253.